package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.common.utils.UUIDUtils;
import com.party.core.dao.read.mall.MallCategoryBrandReadDao;
import com.party.core.dao.write.mall.MallCategoryBrandWriteDao;
import com.party.core.model.mall.MallCategoryBrand;
import com.party.core.service.mall.IMallCategoryBrandService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Set;

/**
 * @Author: Administrator.
 * @Description: 商城分类规格接口实现
 * @Date:Created in 2017/8/22 0022 下午 15:14.
 */
@Service
public class MallCategoryBrandService implements IMallCategoryBrandService {

    @Autowired
    private MallCategoryBrandReadDao mallCategoryBrandReadDao;
    @Autowired
    private MallCategoryBrandWriteDao mallCategoryBrandWriteDao;

    /**
     * 规格关系插入
     *
     * @param mallCategoryBrand 规格
     * @return 插入结果
     */
    @Override
    public String insert(MallCategoryBrand mallCategoryBrand) {
        mallCategoryBrand.setId(UUIDUtils.generateRandomUUID());
        boolean result = mallCategoryBrandWriteDao.insert(mallCategoryBrand);
        if (result) {
            return mallCategoryBrand.getId();
        }
        return null;
    }

    /**
     * 规格关系更新
     *
     * @param mallCategoryBrand 规格
     * @return 更新结果（true/false）
     */
    @Override
    public boolean update(MallCategoryBrand mallCategoryBrand) {
        return mallCategoryBrandWriteDao.update(mallCategoryBrand);
    }

    /**
     * 逻辑删除
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallCategoryBrandWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     *
     * @param id 实体主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallCategoryBrandWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallCategoryBrandWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量删除
     *
     * @param ids 主键集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallCategoryBrandWriteDao.batchDelete(ids);
    }

    /**
     * 获取
     *
     * @param id 主键
     * @return 规格
     */
    @Override
    public MallCategoryBrand get(String id) {
        return mallCategoryBrandReadDao.get(id);
    }

    /**
     * 分页查询
     *
     * @param mallCategoryBrand 规格
     * @param page              分页信息
     * @return 列表
     */
    @Override
    public List<MallCategoryBrand> listPage(MallCategoryBrand mallCategoryBrand, Page page) {
        return mallCategoryBrandReadDao.listPage(mallCategoryBrand, page);
    }

    /**
     * 查询所有
     *
     * @param mallCategoryBrand 规格
     * @return 列表
     */
    @Override
    public List<MallCategoryBrand> list(MallCategoryBrand mallCategoryBrand) {
        return mallCategoryBrandReadDao.listPage(mallCategoryBrand, null);
    }

    @Override
    public List<MallCategoryBrand> batchList(@NotNull Set<String> ids, MallCategoryBrand mallCategoryBrand, Page page) {
        return null;
    }

    @Override
    public void deleteByUnique(MallCategoryBrand mallCategoryBrand) {
        mallCategoryBrandWriteDao.deleteByUnique(mallCategoryBrand);
    }

    @Override
    public List<MallCategoryBrand> findByBrandId(String brandId) {
        MallCategoryBrand categoryBrand = new MallCategoryBrand();
        categoryBrand.setBrandId(brandId);
        return mallCategoryBrandReadDao.listPage(categoryBrand, null);
    }

    @Override
    public MallCategoryBrand getUnique(MallCategoryBrand mallCategoryBrand) {
        return mallCategoryBrandReadDao.getUnique(mallCategoryBrand);
    }

    @Override
    public List<MallCategoryBrand> findByCategoryId(String categoryId) {
        MallCategoryBrand categoryBrand = new MallCategoryBrand();
        categoryBrand.setCategoryId(categoryId);
        return mallCategoryBrandReadDao.listPage(categoryBrand, null);
    }

    @Override
    public void deleteByCategoryId(String categoryId) {
        mallCategoryBrandWriteDao.deleteByCategoryId(categoryId);
    }
}
